<?php

namespace App\Traits\Relation\Inspection;

use App\Models\Inspection;
use App\Models\Inspection\Circle;
use Illuminate\Database\Eloquent\Relations\HasMany;

/**
 * 定义节点模型关系
 *
 * Trait NodeRelation
 * @package App\Traits\Relation\Inspection
 * Date: 22/04/2018
 * @author George
 */
trait NodeRelation
{
    /**
     * 获取点位所属的圈信息
     *
     * Date: 22/04/2018
     * @author George
     * @return mixed
     */
    public function circle()
    {
        return $this->belongsTo(Circle::class, 'circle_id', 'id');
    }

	/**
	 * 获取几点的巡检数据
	 *
	 * Date: 01/05/2018
	 * @author George
	 * @return HasMany
	 */
	public function inspections()
	{
		return $this->hasMany(Inspection::class, 'node_id', 'id')->whereDate('created_at', date('Y-m-d'));
    }
}
